const generalConfig = (data, toolFn) => {
  let legendData = data?.map((item) => {
    return {
      name: item?.name || '',
      itemStyle: {
        color: '#272829',
        borderColor: item?.color || '',
        borderWidth: 1,
      },
    };
  });
  return {
    xAxis: {
      type: 'category',
      nameTextStyle: { color: '#888E95' },
      axisLabel: { color: '#888E95' },
      axisLine: { lineStyle: { color: '#D1D9E9' } },
      axisTick: { show: false },
    },
    grid: { top: 20, left: 50, right: 50, bottom: 60 },
    legend: {
      bottom: 10,
      textStyle: { color: 'rgba(255,255,255,0.5)', fontSize: 12 },
      data: legendData,
      inactiveColor: '#545454',
      inactiveBorderColor: '#545454',
      inactiveBorderWidth: 'inherit',
    },
    dataZoom: [
      {
        type: 'slider',
        right: 50,
        height: 14,
        bottom: '10%',
        left: '20',
        show: false,
        minSpan: 1,
        throttle: 50,
        dataBackground: {
          areaStyle: {
            color: '#757575',
          },
        },
      },
      {
        type: 'inside',
        show: false,
        minSpan: 1,
        throttle: 500,
      },
    ],
    yAxis: {
      type: 'value',
      nameTextStyle: { color: '#888E95' },
      axisLabel: { color: '#888E95' },
      splitLine: { lineStyle: { color: '#464646' } },
    },
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        type: 'cross',
        label: {
          backgroundColor: '#444444',
          color: '#888E95',
          shadowBlur: 0,
        },
      },
      formatter: (val) => {
        toolFn(val);
        return;
      },
    },
  };
};
const keyWord = ['typeLink', 'id', 'color', 'type', 'isSum'];
export const getPowerCharts = (data, toolFn) => {
  const seriesData = data.map((item) => {
    let data = [];
    Object.entries(item).map(([k, i]) => {
      if (!keyWord.includes(k)) {
        data.push({
          xAxis: k.replace(/\./g, '').replace(':', ''),
          value: i,
        });
      }
    });
    data = data.sort((a, b) => {
      return Number(a.xAxis.replace(/\s*/g, '')) - Number(b.xAxis.replace(/\s*/g, ''));
    });
    return {
      name: item.typeLink,
      id: item.id,
      color: item.color,
      type: item.type,
      data: data,
      symbol: 'circle',
      symbolSize: 0,
      itemStyle: {
        lineStyle: {
          width: 1,
        },
      },
    };
  });
  let xAxisData = seriesData?.[0]?.data?.map((item) => item?.xAxis);
  return {
    ...generalConfig(seriesData, toolFn),
    xAxis: {
      data: xAxisData,
    },
    series: seriesData,
  };
};
